<?php
namespace app\home\controller;

use app\common\access\MyAccess;
use app\common\service\Action;
use think\Controller;
use think\Request;

class Index extends Controller
{
    public function _initialize()
    {
        $request = Request::instance();
        $root=$request->root();
        $action=$root.'/'.$request->module().'/'.$request->controller().'/'.$request->action();
        $this->assign("ROOT", $root);
        $this->assign("ACTION",$action);

        $this->assign("TITLE", TITLE);
        $this->assign("COPYRIGHT", COPYRIGHT);
    }

    public function index(){
        try {
            MyAccess::checkAccess('R');
            $userinfo = null;
            $userinfo['username'] = session('S_USER_NAME');//用户名登录名
            $userinfo['realname'] = session('S_TEACHER_NAME');//真实姓名
            $userinfo['teacherno'] = session('S_TEACHERNO');//真实姓名
            $userinfo['school'] = session('S_USER_SCHOOL'); //所在学院代码
            $userinfo['schoolname'] = session('S_USER_SCHOOL_NAME');//学院名称
            $userinfo['manage'] = session('S_MANAGE');//是否主管部门1是/0否
            $this->assign('USERINFO', $userinfo);

            $Obj = new Action();
            $menuJson = array('menus' => $Obj->getUserAccessMenu(session('S_USER_NAME'), 230));
            $this->assign('menu', json_encode($menuJson));
            return $this->fetch();
        }
        catch (\Exception $e) {
            MyAccess::throwException($e->getCode(),$e->getMessage());
        }
    }

    public function login()
    {
        try{
            $guid = getGUID(session_id());
            session('S_GUID', $guid);
            $this->assign('GUID', $guid);
            return $this->fetch();
        }
        catch (\Exception $e) {
            MyAccess::throwException($e->getCode(),$e->getMessage());
        }
    }
}
